package app.inmos.adapters;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import app.inmos.exception.ImagenNoEncontradaException;
import app.inmos.functions.json.ImageUtilsJSON;
import app.inmos.utils.ImageUtils;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
 
    // Keep all Images in array
    public String[] imagenes;
    
   
   
 
    // Constructor
    public ImageAdapter(ImageUtilsJSON pImageUtilJSON,Context pContext){	
    	setImagenes(pImageUtilJSON.getListaPathImagenes());
    	mContext=pContext;
    }
 
    @Override
    public int getCount() {
        return imagenes.length;
    }
 
    @Override
    public Object getItem(int position) {
        return imagenes[position];
    }
 
    @Override
    public long getItemId(int position) {
        return 0;
    }
 
    @Override
    public View getView(int pPostion, View convertView, ViewGroup parent) {
        
    	ImageView imageView = new ImageView(mContext);
        
        try {
        	
			imageView.setImageBitmap(ImageUtils.getInstance().obtenerImagen(imagenes[pPostion]));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
            
        
    	} catch (ImagenNoEncontradaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return imageView;
    	
    }

	public String[] getImagenes() {
		return imagenes;
	}

	public void setImagenes(String[] imagenes) {
		this.imagenes = imagenes;
	}

	
	
 


}
